package com.jams.goodox.adapter.lfadapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jams.goodox.R;
import com.jams.goodox.activity.qa.GlideCircleTransform;
import com.jams.goodox.activity.qa.entity.CourseData;
import com.jams.goodox.entity.ClassRoomBean;

import java.util.List;


/**
 * Created by HP on 2018/5/12.
 */

public class ClassRoomAdapter extends RecyclerView.Adapter<ClassRoomAdapter.TViewHolder> {

    private Context context;

    private List<CourseData> list;

    private OnItemClickListener onItemClickListener;


    public interface OnItemClickListener {
        void OnItemClick(View view, ClassRoomAdapter.TViewHolder holder, int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.onItemClickListener = listener;
    }


    public ClassRoomAdapter(Context context, List<CourseData> list ) {
        this.context = context;
        this.list = list;
    }


    @Override
    public ClassRoomAdapter.TViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.classroom_item2,
                parent,false);
        ClassRoomAdapter.TViewHolder th = new ClassRoomAdapter.TViewHolder(v);

        return th;
    }

    @Override
    public void onBindViewHolder(ClassRoomAdapter.TViewHolder holder, int position) {
        CourseData classRoomBean = list.get(position);
        holder.title.setText(classRoomBean.getTitle());
        holder.content.setText(classRoomBean.getContent());
        if(classRoomBean.getPrice() > 0){
            holder.price.setText((int)classRoomBean.getPrice() + "氧币");
        }else {
            holder.price.setVisibility(View.GONE);
        }
        holder.nickName.setText(classRoomBean.getNickName());
        //Glide.with(context).load(classRoomBean.getImgPath()).into(holder.imageView);
        holder.imageView.setImageURI(Uri.parse(classRoomBean.getImgPath()));
//        Glide.with(context).load(classRoomBean.getImgPath())
//                .placeholder(R.drawable.loading) //占位符 也就是加载中的图片，可放个gif
//                .error(R.mipmap.morentouxiang60) //失败图片
//                .bitmapTransform(new GlideCircleTransform(context)).crossFade(1000).into(holder.imageView);

    }

    @Override
    public int getItemCount() {
        return list.isEmpty()? 0 : list.size();
    }


    public class TViewHolder extends RecyclerView.ViewHolder{
        public TextView title;
        public TextView price;

        private TextView content;
        public TextView nickName;
        public SimpleDraweeView imageView;


        public TViewHolder(View itemView) {
            super(itemView);
            title = (TextView)itemView.findViewById(R.id.title);
            price = (TextView)itemView.findViewById(R.id.price);
            content = (TextView)itemView.findViewById(R.id.content);
            nickName = (TextView)itemView.findViewById(R.id.nickName);
            imageView = (SimpleDraweeView) itemView.findViewById(R.id.imageView);
        }
    }
}
